package com.shop.shoppingmall.controller;

import com.shop.shoppingmall.entity.ShInproduct;
import com.shop.shoppingmall.service.ShInproductService;
import com.shop.shoppingmall.util.api.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (ShInproduct)表控制层
 *
 * @author makejava
 * @since 2021-02-18 16:08:26
 */
@RestController
@CrossOrigin
@RequestMapping("shInproduct")
public class ShInproductController {
    /**
     * 服务对象
     */
    @Resource
    private ShInproductService shInproductService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ShInproduct selectOne(String id) {
        return this.shInproductService.queryById(id);
    }

    /**
     *      后 台
     * 商品的 增 删 改 查
     *
     */
    @RequestMapping("/add")
    public Result add(@RequestBody ShInproduct shInproduct){
        return shInproductService.add(shInproduct);
    }

    /**
     * 通过id删除商品信息
     */
    @RequestMapping("/deleteById")
    public Result deleteById(@RequestBody Map map){
        boolean b = shInproductService.deleteById((String) map.get("id"));
        if (b){
            return Result.ok("商品删除成功");
        }else {
            return Result.error("商品删除失败，请稍后重试");
        }
    }

    /**
     * 通过id修改商品信息
     */
    @RequestMapping("/editById")
    public Result editById(@RequestBody ShInproduct shInproduct){
        return shInproductService.editById(shInproduct);
    }

    /**
     * 通过id查询商品
     */
    @RequestMapping("/searchById")
    public Result searchById(@RequestBody Map map){
        return shInproductService.searchById(map);
    }

    /**
     * 查询所有兑换商品
     */
    @RequestMapping("/searchAll")
    public Result searchAll(){
        return shInproductService.searchAll();
    }


}















